#include "user.h"
#include "xors3d.h"


User::User(float x, float y, float z)
{
	speed = 0.1f;
	moveToGoal = false;
	CreateUser(x, y, z);
}

void User::CreateUser(float x, float y, float z)
{
	sphere = xCreateSphere();
	xPositionEntity(sphere, x, y, z);

	camera = xCreateCamera(sphere);
	xPositionEntity(camera, 15, -15, -20);
	xRotateEntity(camera, -30, 30, 45);
}

void User::Update()
{
	Move();
}

void User::Move()
{
	if(moveToGoal)
	{
		if(xKeyDown(KEY_A)) { xMoveEntity(sphere, -speed, 0, 0); ResetGoal(); }
		if(xKeyDown(KEY_D)) { xMoveEntity(sphere, speed, 0, 0); ResetGoal(); }
		if(xKeyDown(KEY_W)) { xMoveEntity(sphere, 0, speed, 0); ResetGoal(); }
		if(xKeyDown(KEY_S)) { xMoveEntity(sphere, 0, -speed, 0); ResetGoal(); }
	}
}

void ResetGoal()
{
	moveToGoal = false;
}

void User::SetGoal(float x, float y, float z)
{
	goalPivot = xCreatePivot();
	xPositionEntity(goalPivot, x, y, z);
	moveToGoal = true;
}